#include <stdio.h>
#include <stdlib.h>

int cmp_arr(const void*p1, const void*p2)
{
	if (*(int*)p1 > *(int*)p2)
	{
		return 1;
	}
	else if (*(int*)p1 == *(int*)p2)
	{
		return 0;
	}
	else
	{
		return -1;
	}
}

int main()
{
	int n;
	int a[10000];
	int b[20000];
	scanf_s("%d", &n);
	int count[10000] = { 0 };
	for (int i = 1; i <= n; i++)
	{
		scanf_s("%d%d", &a[i], &b[i]);
		count[a[i]]++;
	}
	int sz = sizeof(a) / sizeof(a[1]);
	int sz1 = sizeof(b) / sizeof(b[1]);
	int sum = 0;
	int k = 1;
	qsort(a, sz, sizeof(a[1]), cmp_arr);
	/*qsort(b, sz1, sizeof(b[1]), cmp_arr);*/
	for (int i = 1; i<n; i++)
	{
		if (count[i]>1)
		{
			for (int j = 1; j<count[i]; j++)
			{
				sum += b[k];
				k++;
			}			
		}
		if (count[i]!=0) k++;
	}
	printf("%d\n", sum);
	return 0;
}